﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace MonitoringFloty_WindowsPhoneClient
{
    public partial class DeviceIdSetup : PhoneApplicationPage
    {
        positionUpdater updater = positionUpdater.Instance;
        public DeviceIdSetup()
        {
            InitializeComponent();
            switch (updater.getInfoName())
            {
                case positionUpdater.testEnum.UniqueID:
                    {
                        radioButton1.IsChecked = true;
                        radioButton2.IsChecked = false;
                        radioButton3.IsChecked = false;
                        radioButton4.IsChecked = false;
                        break;
                    }
                case positionUpdater.testEnum.OperatorName:
                    {
                        radioButton1.IsChecked = false;
                        radioButton2.IsChecked = false;
                        radioButton3.IsChecked = true;
                        radioButton4.IsChecked = false;
                        break;
                    }
                case positionUpdater.testEnum.TelephoneName:
                    {
                        radioButton1.IsChecked = false;
                        radioButton2.IsChecked = true;
                        radioButton3.IsChecked = false;
                        radioButton4.IsChecked = false;
                        break;
                    }
                case positionUpdater.testEnum.OwnString:
                    {
                        radioButton4.IsChecked = true;
                        OwnName.IsEnabled = true;
                        OwnName.Text = updater.OwnInfo;
                        break;
                    }
            }
            //radioButton1.IsChecked = true;
            //OwnName.IsEnabled = false;
        }

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void otherRadios_Checked(object sender, RoutedEventArgs e)
        {
            OwnName.IsEnabled = false;
        }

        private void radioButton4_Checked(object sender, RoutedEventArgs e)
        {
            OwnName.IsEnabled = true;
        }

        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
           // NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
            NavigationService.GoBack();
        }

        private void OkBtn_Click(object sender, RoutedEventArgs e)
        {
            
            if (radioButton1.IsChecked.Value)
                updater.setInfoName(positionUpdater.testEnum.UniqueID);
            if (radioButton2.IsChecked.Value)
                updater.setInfoName(positionUpdater.testEnum.TelephoneName);
            if (radioButton3.IsChecked.Value)
                updater.setInfoName(positionUpdater.testEnum.OperatorName);
            if (radioButton4.IsChecked.Value)
            {
                updater.OwnInfo = OwnName.Text;
                updater.setInfoName(positionUpdater.testEnum.OwnString);
            }
            NavigationService.GoBack();
        }
    }
}